class_name Card extends Resource

enum Rarity {COMMON, UNCOMMON, RARE}
enum Type {ATTACK, SKILL, POWER}
enum Target {SELF, SINGLE_ENEMY, ALL_ENEMYIES, EVERYONE}

const RARITY_COLOR := {
	Rarity.COMMON: Color.GRAY,
	Rarity.UNCOMMON: Color.CORNFLOWER_BLUE,
	Rarity.RARE: Color.GOLD
}
@export_group("Card Attributes")
@export var id: String
@export var type: Type
@export var rarity: Rarity
@export var target: Target
@export var cost: int
@export var exhausts: bool = false

@export_group("Card Visuals")
@export var icon: Texture
@export_multiline var tooltip_text: String
@export var sound: AudioStream

func is_single_target() -> bool:
	return target == Target.SINGLE_ENEMY

func _get_targets(targets: Array[Node]) -> Array[Node]:
	if targets.is_empty():
		return []
	var tree = targets[0].get_tree()
	match target:
		Target.SELF:
			return tree.get_nodes_in_group("player")
		Target.ALL_ENEMYIES:
			return tree.get_nodes_in_group("enemy")
		Target.EVERYONE:
			return tree.get_nodes_in_group("player") + tree.get_nodes_in_group("enemy")
		_:
			return []
			
func play(targets: Array[Node], char_stats: CharacterStats, modifier_handler: ModifierHandler) -> void:
	Events.do_card_played(self)
	char_stats.mana -= cost
	if is_single_target():
		apply_effects(targets, modifier_handler)
	else:
		apply_effects(_get_targets(targets), modifier_handler)


func apply_effects(_targets:Array[Node], _modifier_handler: ModifierHandler) -> void:
	pass

func get_default_tooltip() -> String:
	return tooltip_text
	
func get_update_tooltip(_player_modifier: ModifierHandler, _enemy_modifier: ModifierHandler) -> String:
	return get_default_tooltip()
